A guide to optimizing Unity UI

译文

A guide to optimizing Unity UI
Unity UI 优化指南

版本检查: 2017.3
难度: 高级

Optimizing a user interface driven by Unity UI is an art. Hard-and-fast rules are rare; instead, each situation must be carefully evaluated with the system’s behavior in mind. The core tension when optimizing any Unity UI is the balancing of draw calls with batching costs. While some common-sense techniques can be used to reduce one or the other, complex UIs must make trade-offs.
优化Unity UI驱动的用户界面是一门艺术。现阶段简单明了的优化规则很少,对每一种情况都必须针对系统行为作出很详细的评估。考虑优化Unity UI时最核心的原则是结合开销,平衡draw calls和批处理成本,复杂的UI 需要做权衡。

However, as is best practice elsewhere, attempts to optimize Unity UIs should begin with profiling. The primary task before attempting to optimize a Unity UI system is to locate the precise reason for an observed performance problem. There are four common classes of problems encountered by users of Unity UI:
然而,正如其他地方的最佳做法一样,优化Unity UI的尝试应该从分析开始。尝试优化Unity UI系统之前的主要任务是找到性能问题的确切原因。Unity UI用户遇到四种常见问题:

      ●  Excessive GPU fragment shader utilization (i.e. fill-rate overutilization)
          过多的GPU片段着色器利用率(即填充率过度使用)

      ●  Excessive CPU time spent rebuilding a Canvas batch
          重建Canvas批处理所花费的CPU时间过长

      ●  Excessive numbers of rebuilds of Canvas batches (over-dirtying)
          过多的Canvas批次重建(过度污染)

      ●  Excessive CPU time spent generating vertices (usually from text)
          生成顶点所花费的CPU时间过长(通常来自文本)

It is, in principle, possible to create a Unity UI whose performance is constrained by the sheer number of draw calls being sent to the GPU. However, in practice, any project overloading the GPU with draw calls is more likely to be bound by fill-rate overutilization.
原则上,创建一个Unity UI,它的性能是由送到GPU的draw calls数量限制。然而,实际上,任何项目超载draw call调用GPU,都更容易被填充率过度使用约束。

This guide will discuss the fundamental concepts, algorithms and code underlying Unity UI as well as discussing common problems and solutions. It is broken into five chapters:
本指南将讨论Unity UI的基本概念,算法和代码,以及常见的问题和解决方法。它分为五章:

      1.  The Fundamentals of Unity UI chapter defines terminology specific to Unity UI and discusses the details of many of the fundamental processes performed to render the UI, including the building of batched geometry. It is strongly recommended that readers begin with this chapter.
       Unity UI基础知识,这章解释了Unity UI专用术语,讨论了渲染UI一些基本过程的细节,包括批处理几何图形。强烈建议读者从这章开始学习。

      2.  The Unity UI profiling tools chapter discusses gathering profiling data with the various tools available to developers.
       Unity UI性能分析工具,本章讨论收集与提供给开发者的各种工具分析数据。

      3.  The Fill-rate, Canvases and input chapter discusses ways to improve the performance of Unity UI's Canvas and Input Components.
       填充率、画布和输入,本章讨论了改善用户界面的Canvas和输入组件的性能的方法。

      4.  The UI controls chapter discusses UI Text, Scroll Views and other component-specific optimizations, along with some techniques that do not fit well elsewhere.
       UI控件,本章讨论UI文本(UI Text),滚动视图(Scroll View)和其他特定组件的优化。

      5.  The Other techniques and tips chapter discusses a handful of issues that do not fit elsewhere, including some basic tips and workarounds for "gotchas" in the UI system.
       UI优化的其他技术和技巧。本章讨论了一些在少数地方不适用的情况,包括一些技巧和UI系统中的一些陷阱。

UI Source Code
UI 源代码

Always remember that Unity UI’s Graphic and Layout components are entirely open source. Their source code can be found on Unity’s Bitbucket repository, under UI.
记住,Unity UI图形和布局组件是完全开源的。他们的源代码可以在UI的Bitbucket存储库中找到。


相关链接

  1. 原文地址: https://unity3d.com/cn/learn/tutorials/topics/best-practices/guide-optimizing-unity-ui?playlist=30089